package com.zut.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zut.dao.BusinessDao;
import com.zut.dao.EmployeeDao;
import com.zut.pojo.Business;
import com.zut.pojo.PageInfo;
import com.zut.service.BusinessService;
import com.zut.utils.MybatisUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 张晨
 * @date 2024/9/10 16:43
 * @desc
 */
public class BusinessServiceImpl implements BusinessService {
    private BusinessDao businessDao;
    {
        businessDao = MybatisUtil.getSqlSession().getMapper(BusinessDao.class);
    }
    @Override
    public Integer register(Business business) {
            return businessDao.insertBusiness(business);
    }

    @Override
    public Business login(String account, String password) {
            return businessDao.selectAccountAndPassword(account,password);
    }

    @Override
    public PageInfo conditionSelect(Business business, Integer currentPage, Integer pageSize) {
        Page<Business> page = null;
        List<Business> result = new ArrayList<>();
        try {
            PageHelper.startPage(currentPage, pageSize);
            page = businessDao.selectByContactAndTelephone(business);
            for (Business business1 : page) {
                result.add(business1);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        PageInfo<Business> pageInfo = new PageInfo<>();
        pageInfo.setList(result);
        pageInfo.setTotal(page.getTotal());
        return pageInfo;
    }
    @Override
    public Integer deletebusinessById(int i) {
        return businessDao.deleteById(i);
    }

    @Override
    public Integer updateById(Business business) {
        return businessDao.updateById(business);
    }
}
